package logic

import (
	"context"
	"gorm.io/gorm"
	"zg1/user-profile/models/mysql"

	"zg1/user-profile/userRpc/internal/svc"
	"zg1/user-profile/userRpc/userRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *userRpc.UpdateRequest) (*userRpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.UserZy{
		Model: gorm.Model{ID: uint(in.UserId)},
		Image: in.Image,
		Name:  in.Name,
		Info:  in.Info,
	}

	mysql.DB.Updates(&user)

	return &userRpc.UpdateResponse{
		UserId: int64(user.ID),
	}, nil
}
